package com.wz.project.bas.nowClass.controller;

import com.wz.framework.web.controller.BaseController;
import com.wz.framework.web.domain.AjaxResult;
import com.wz.framework.web.page.TableDataInfo;
import com.wz.project.bas.nowClass.domain.NowClass;
import com.wz.project.bas.nowClass.service.INowClassService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 当前班组 信息操作处理
 * 
 * @author sys
 * @date 2021-10-29
 */
@Controller
@RequestMapping("/bas/nowClass")
public class NowClassController extends BaseController
{
    private String prefix = "bas/nowClass";
	
	@Autowired
	private INowClassService nowClassService;
	
//	@RequiresPermissions("bas:nowClass:view")
	@GetMapping()
	public String nowClass()
	{
	    return prefix + "/nowClass";
	}
	
	/**
	 * 查询当前班组列表
	 */
//	@RequiresPermissions("module:nowClass:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(NowClass nowClass)
	{
		startPage();
        List<NowClass> list = nowClassService.selectNowClassList(nowClass);
		return getDataTable(list);
	}
	
	/**
	 * 新增当前班组
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存当前班组
	 */
	@RequiresPermissions("module:nowClass:add")
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(NowClass nowClass)
	{
		String s = String.valueOf(System.currentTimeMillis());
		String substring = s.substring(s.length() - 6);
//        int pejId = Integer.parseInt(substring);
		nowClass.setClassId(substring);
		return toAjax(nowClassService.insertNowClass(nowClass));
	}

	/**
	 * 修改当前班组
	 */
	@GetMapping("/edit/{classId}")
	public String edit(@PathVariable("classId") String classId, ModelMap mmap)
	{
		NowClass nowClass = nowClassService.selectNowClassById(classId);
		mmap.put("nowClass", nowClass);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存当前班组
	 */
	@RequiresPermissions("module:nowClass:edit")
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(NowClass nowClass)
	{		
		return toAjax(nowClassService.updateNowClass(nowClass));
	}
	
	/**
	 * 删除当前班组
	 */
	@RequiresPermissions("module:nowClass:remove")
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(nowClassService.deleteNowClassByIds(ids));
	}
	
}
